package com.jubotech.business.web.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jubotech.business.web.dao.SysBlackWxDao;
import com.jubotech.business.web.domain.CustomerInfo;
import com.jubotech.business.web.domain.SysBlackWx;
import com.jubotech.business.web.domain.SysConfig;
import com.jubotech.business.web.query.blackQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional // 支持事务
@CacheConfig(cacheNames="sysBlack")
public class SysBlackWxService {

    @Autowired
    private SysBlackWxDao sysBlackWxDao;

    public SysBlackWx insert(SysBlackWx info) {
        sysBlackWxDao.insert(info);
        return info;
    }

    @CacheEvict(/*value="system",*/allEntries=true)
    public int delete(String wxid) {
        return sysBlackWxDao.deleteByWxid(wxid);
    }

    @Cacheable(key = "#wechatId")
    public List<SysBlackWx> getByWechatId(String wechatId) {
        return sysBlackWxDao.getByWechatId(wechatId);
    }

    public PageInfo<SysBlackWx> pageList(blackQuery query) {
        PageHelper.startPage(query.getPage(), query.getRows());
        return new PageInfo<>(sysBlackWxDao.pageList(query));
    }
}
